package com.input4hua.observer.subject;

import com.input4hua.observer.observer.Observer;

import java.util.Vector;

/**
 * Created by jiahua.hu on 2019/2/16.
 */
public abstract class Subject {

    private Vector<Observer> observers = new Vector<>();

    //增加观察者
    public void addObserver(Observer o){
        this.observers.add(o);
    }

    //移除观察者
    public void removeObserver(Observer o){
        this.observers.remove(o);
    }

    public void notifyObservers(String message){
        for(Observer o : this.observers){
            o.update(this,message);
        }
    }
}
